package core.manager.playerManager.flvPlayerManager
{
    import core.manager.sceneManager.*;
    import core.manager.scriptManager.*;
    import flash.events.*;
    import mx.core.*;
    import util.view.player.*;
    import util.view.player.event.*;

    public class FlvBase extends UIComponent
    {
        private var readyScript:String = "";
        private var flvPlayer:FLVPlayer;
        private var completeSript:String = "";

        public function FlvBase(path:String,width:Number, height:Number,autoPlay:int, readyScript:String, completeSript:String,canSkip:int)
        {
            this.readyScript = readyScript;
            this.completeSript = completeSript;
            var _loc_8:Boolean;
            if (autoPlay == 1)
            {
                _loc_8 = true;
            }
            initPlayer(path, width,height , _loc_8, true,canSkip );
            return;
        }// end function

        private function on_complete(particles:FLVPlayerEvent) : void
        {
            flvPlayer.resume();
            return;
        }// end function

        private function onReady(particles:FLVPlayerEvent) : void
        {
            ScriptManager.getInstance().runScriptDirectly(readyScript);
            return;
        }// end function

        private function on_play_complete(particles:NetStatusEvent) : void
        {
            runCompleteScript();
            return;
        }// end function

        private function runCompleteScript() : void
        {
            ScriptManager.getInstance().runScriptDirectly(completeSript);
            return;
        }// end function

        public function initPlayer(path:String, width:Number, height:Number, autoPlay:Boolean, particles:Boolean = false, canSkip:int = 0) : void
        {
            flvPlayer = new FLVPlayer(path,width,height,true,autoPlay,canSkip);
            this.addChild(flvPlayer);
            flvPlayer.y = 70;
            flvPlayer.addEventListener(NetStatusEvent.NET_STATUS, on_play_complete);
            flvPlayer.addEventListener(Event.CLOSE, onClose);
            flvPlayer.addEventListener(FLVPlayerEvent.COMPLETE, on_complete);
            flvPlayer.addEventListener(FLVPlayerEvent.READY, onReady);
            SceneManager.getInstance().addEventListener(SceneChangeEvent.COMPLETE, dispose);
            return;
        }// end function

        private function onClose(particles:Event) : void
        {
            this.dispatchEvent(new Event(Event.CLOSE));
            flvPlayer.removeEventListener(Event.CLOSE, onClose);
            flvPlayer.removeEventListener(NetStatusEvent.NET_STATUS, on_play_complete);
            flvPlayer.pause();
            runCompleteScript();
            return;
        }// end function

        public function dispose(particles:SceneChangeEvent) : void
        {
            if (flvPlayer != null)
            {
                flvPlayer.pause();
                flvPlayer.parent.removeChild(flvPlayer);
                flvPlayer.dispose();
                flvPlayer = null;
            }
            return;
        }// end function

    }
}
